Sanity checking the CIC Emu to make sure nothing went wrong there.
In [33]:
import matplotlib
#matplotlib.use('Agg')
from matplotlib import pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()
In [34]:
from pearce.emulator import NashvilleHot
In [35]:
from GPy.kern import *
In [36]:
import numpy as np
from os import path
In [37]:
training_file = '/u/ki/swmclau2/des/cic_zheng07_v3/PearceCICCosmo.hdf5'
In [38]:
em_method = 'gp'
In [39]:
fixed_params = {'z':0.0}
In [40]:
hyperparams = {'kernel': (Linear(input_dim=7, ARD=True) + RBF(input_dim=7, ARD=True)+Bias(input_dim=7),
RBF(input_dim=5, ARD=True)+Bias(input_dim=5) ), \
'optimize': True}
In [41]:
df = 0.1
In [42]:
emu = NashvilleHot(training_file, fixed_params = fixed_params,\
downsample_factor = df, hyperparams=hyperparams)
In [66]:
#test_file = '/home/users/swmclau2/scratch/cic_zheng07_test_v2/PearceCICCosmoTest.hdf5'
test_file = '/u/ki/swmclau2/des/cic_zheng07_v3_test/PearceCICCosmoTest.hdf5'
In [67]:
pred_y, data_y = emu.goodness_of_fit(test_file, statistic = None)
In [68]:
print (np.abs(10**pred_y - 10**data_y)/(10**data_y)).mean(axis =1)
In [69]:
print (np.abs(pred_y - data_y)/np.abs(data_y)).mean(axis =1)
In [70]:
emu._y_mean
Out[70]:
In [71]:
idx = 100
In [72]:
for idx in np.random.choice(pred_y.shape[1], 20, replace = False):
plt.plot(emu.scale_bin_centers, 10**pred_y[:, idx], label = 'Emu')
plt.plot(emu.scale_bin_centers, 10**data_y[:, idx], label = 'True')
plt.plot(emu.scale_bin_centers, 10**emu._y_mean, label = 'Mean')
#plt.yscale('log')
plt.loglog();
plt.legend(loc = 'best')
plt.show();
In [73]:
for idx in np.random.choice(pred_y.shape[1], 20, replace = False):
plt.plot(emu.scale_bin_centers[:10], 10**pred_y[:10, idx], label = 'Emu')
plt.plot(emu.scale_bin_centers[:10], 10**data_y[:10, idx], label = 'True')
plt.plot(emu.scale_bin_centers[:10], 10**emu._y_mean[:10], label = 'Mean')
#plt.yscale('log')
plt.loglog();
plt.legend(loc = 'best')
plt.show();
In [74]:
test_mean = data_y.mean(axis = 1)
test_std = data_y.std(axis = 1)
In [75]:
data = emu.y.reshape((15, -1))
In [76]:
data = data*emu._y_std.reshape((-1, 1)) + emu._y_mean.reshape((-1,1))
In [77]:
data.shape
Out[77]:
In [78]:
train_mean = data.mean(axis = 1 )
train_std = data.std(axis = 1)
In [79]:
plt.plot(emu.scale_bin_centers, 10**test_mean, label = 'Test Mean')
plt.plot(emu.scale_bin_centers, 10**train_mean, label = 'Train Mean')
#plt.yscale('log')
plt.loglog();
plt.legend(loc = 'best')
plt.show();
In [80]:
plt.plot(emu.scale_bin_centers, train_mean/test_mean)
plt.plot(emu.scale_bin_centers, np.ones_like(emu.scale_bin_centers), ls = '--')
plt.xscale('log')
#plt.loglog();
#plt.legend(loc = 'best')
plt.show();
In [81]:
plt.plot(emu.scale_bin_centers, train_std, label = 'Train')
plt.plot(emu.scale_bin_centers, test_std, label = 'Test')
plt.legend(loc='best')
plt.xscale('log')
plt.show();
In [82]:
plt.plot(emu.scale_bin_centers, train_std/test_std)
plt.plot(emu.scale_bin_centers, np.ones_like(emu.scale_bin_centers), ls = '--')
plt.xscale('log')
#plt.loglog();
#plt.legend(loc = 'best')
plt.show();
In [83]:
emu.scale_bin_centers
Out[83]:
In [84]:
import h5py
test_mean = np.zeros((15,))
with h5py.File(test_file, 'r') as f:
for key in f.keys():
test_mean+=f[key]['a_1.000']['obs'][()].mean(axis = 0)
test_mean/=35
In [85]:
import h5py
train_mean = np.zeros((15,))
with h5py.File(training_file, 'r') as f:
for key in f.keys():
train_mean+=f[key]['a_1.000']['obs'][()].mean(axis = 0)
train_mean/=40
In [86]:
plt.plot(emu.scale_bin_centers, test_mean, color = 'r')
plt.plot(emu.scale_bin_centers, train_mean, color = 'b')
plt.xscale('log')
In [87]:
train_mean
Out[87]:
In [ ]: